package com.zzh.util;


import com.alibaba.fastjson.JSONObject;

public class BaseResultInfo {
    /**
     * 返回的提示消息
     */
    private String message;

    private Long count = 1000L; //备用字段，临时默认值

    private Object data;
    /**
     * 返回的标志位
     */
    private int flag;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public int getFlag() {
        return flag;
    }

    public void setFlag(int flag) {
        this.flag = flag;
    }

    public Long getCount() {
        return count;
    }

    public void setCount(Long count) {
        this.count = count;
    }

    @Override
    public String toString(){
        return JSONObject.toJSONString(this);
    }

    public static BaseResultInfo successResult(String message, Object data, Long count) {
        BaseResultInfo bri =  new BaseResultInfo();
        bri.setData(data);
        bri.setCount(count);
        bri.setMessage(message);
        bri.setFlag(200);
        return bri;
    }

    public static BaseResultInfo successResult(String message, Object data) {
        return successResult(message, data, null);
    }

    public static BaseResultInfo successResult(String message){
        return successResult(message, null, null);
    }

    public static BaseResultInfo failResult(Integer flag, String message, Object data) {
        BaseResultInfo bri =  new BaseResultInfo();
        bri.setData(data);
        bri.setMessage(message);
        bri.setFlag(flag);
        return bri;
    }

    public static BaseResultInfo failResult(Integer flag, String message){
        return failResult(flag, message, null);
    }
    public static BaseResultInfo failResult(String message){
        return failResult(201, message, null);
    }
}
